package cn.tedu.boot22.controller;

import cn.tedu.boot22.entity.Hero;
import cn.tedu.boot22.mapper.HeroMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class HeroController {
    @Autowired
    HeroMapper mapper;


    @RequestMapping("/add")
    @ResponseBody
    public String add(Hero hero){
        System.out.println(hero);
        mapper.insert(hero);
        return "已添加";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public String delete(String name){
        mapper.delete(name);
        return "已删除";
    }

    @RequestMapping("/update")
    @ResponseBody
    public String update(Hero hero){
        mapper.update(hero);
        return "修改完成";
    }

    @RequestMapping("/select")
    @ResponseBody
    public String select(){
        List<Hero> list=mapper.select();
        return list.toString();
    }
}
